/*
 * trace_FunctionInfo.c
 *
 *  Created on: 2012/07/13
 *      Author: guanxiaoying
 */
#include "../table.h"
#include "../trace_cmd_table.h"
typedef struct _TRFUNCTIONINFO
{
	U4 attr;
	AST astFunction;
	AST astPathInfo;
	TRVALUESCP valScp;
} TRFUNCTIONINFO, *PTRFUNCTIONINFO;

#define TableSize  (sizeof(TRFUNCTIONINFO ))
#define TableType  PTRFUNCTIONINFO
#define stTable stTrFunctionManager.memoryBlocks
#define maxTable stTrFunctionManager.maxRecordNum
#define  maxNumPerBlk  (stTrFunctionManager.astMaxNum_Block)


static TABLEMANAGER stTrFunctionManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stTrFunctionManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stTrFunctionManager, resetListener,  index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stTrFunctionManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stTrFunctionManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
static U4 getAttr( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->attr;
}
static U4 setAttr( AST astIndex, U4 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->attr=value;
}

static AST getFunction( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFunction;
}
static AST setFunction( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astFunction=value;
}
static AST getPathInfo( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astPathInfo;
}
static AST setPathInfo( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astPathInfo=value;
}
//static AST getLoopInfo( AST astIndex ){
//	TableType pTbl = core_getTable( astIndex );
//	if( pTbl == NULL )
//	{
//		return 0;
//	}
//	return pTbl->astLoopInfo;
//}
//static AST setLoopInfo( AST astIndex, AST value ){
//	TableType pTbl = core_getTable( astIndex );
//	if( pTbl == NULL )
//	{
//		return 0;
//	}
//	return pTbl->astLoopInfo=value;
//}
static VOID getValueScope( AST astIndex, TRVALUESCP* vs){
	assert( vs != NULL );
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL ){
		return ;
	}
	*vs = pTbl->valScp;
}
static VOID setValueScope( AST astIndex, TRVALUESCP* vs){
	assert( vs != NULL );
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL ){
		return ;
	}
	pTbl->valScp = *vs;
}
const TRFUNCTIONACCESS stTrFunctionAccess={
		ClearTable,
		AllocTable,
		getMaxLineNum,
		{
				getFunction,
				setFunction
		},
		{
				getPathInfo,
				setPathInfo
		},
		{
				getAttr,
				setAttr
		},
		getValueScope,
		setValueScope
};






